﻿using System.Web;
using System.Web.Mvc;

namespace BoneSystem.Extensions.CodeGenerator
{
    public static class DialogGenerator 
    {
        public static MvcHtmlString ModalDialog(string dialogName,int width, string title,HtmlString bodyContent,
            HtmlString bodyFooter)
        {
            var divModal = new AngularTag("div");
            var divModalDialog = new AngularTag("div");
            var divModalContent = new AngularTag("div");
            var divModalHeader = new AngularTag("div");
            var divModalBody = new AngularTag("div");
            var divModalFooter = new AngularTag("div");

            #region Modal

            divModal.Attributes["class"] = "modal fade";
            divModal.Attributes["id"] = dialogName;
            divModal.Attributes["tabindex"] = "-1";
            divModal.Attributes["role"] = "dialog";
            divModal.Attributes["aria-labelledby"] = dialogName + "Label";
            divModal.Attributes["aria-hidden"] = "true";
            //divModal.Attributes["align"] = "left";

            #endregion
            
            #region Modal Dialog

            divModalDialog.Attributes["class"] = "modal-dialog";
            //divModalDialog.Attributes["style"] = "width: "+ width +"px;";

            #endregion
            
            #region Modal Content

            divModalContent.Attributes["class"] = "modal-content";
            //divModalContent.Attributes["style"] = "width: "+ width +"px;";

            #endregion

            #region Modal Header

            divModalHeader.Attributes["class"] = "modal-header";
            //divModalHeader.Attributes["align"] = "center";
            //divModalHeader.Attributes["style"] = "width: "+ width +"px;";

            // Botão de fechamento
            var botao = new AngularTag("button");
            var botaoValue1 = new AngularTag("span");
            var botaoValue2 = new AngularTag("span");
            var tituloH4 = new AngularTag("h4");

            botao.Attributes["type"] = "button";
            botao.Attributes["class"] = "close";
            botao.Attributes["data-dismiss"] = "modal";
            

            botaoValue1.Attributes["aria-hidden"] = "true";

            botaoValue2.Attributes["class"] = "sr-only";

            tituloH4.Attributes["class"] = "modal-title";
            tituloH4.Attributes["id"] = dialogName + "Label";

            tituloH4.InnerHtml = title;

            botao.InnerHtml = botaoValue1.ToString(TagRenderMode.Normal) + botaoValue2.ToString(TagRenderMode.Normal);

            divModalHeader.InnerHtml = botao.ToString(TagRenderMode.Normal) + tituloH4.ToString(TagRenderMode.Normal);

            #endregion
            
            #region Modal body

            divModalBody.Attributes["class"] = "modal-body";
            //divModalBody.Attributes["style"] = "width: "+ width +"px;";

            divModalBody.InnerHtml = bodyContent.ToHtmlString();
            
            #endregion

            #region Modal footer

            divModalFooter.Attributes["class"] = "modal-footer";
            //divModalFooter.Attributes["style"] = "width: "+ width +"px;";

            divModalFooter.InnerHtml = bodyFooter.ToHtmlString();
            #endregion

            divModalContent.InnerHtml = divModalHeader.ToString(TagRenderMode.Normal) + 
                divModalBody.ToString(TagRenderMode.Normal) + 
                divModalFooter.ToString(TagRenderMode.Normal);
            divModalDialog.InnerHtml = divModalContent.ToString();
            divModal.InnerHtml = divModalDialog.ToString();

            return new MvcHtmlString(divModal.ToString(TagRenderMode.Normal));
        }

       
    }
}
